package com.javasm.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.javasm.commons.base.BaseController;
import com.javasm.commons.entity.AxiosResult;
import com.javasm.commons.entity.TableDatas;
import com.javasm.commons.enums.E;
import com.javasm.commons.util.Gi;
import com.javasm.process.entity.ProcessTask;
import com.javasm.process.service.ProcessTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


@RestController
@RequestMapping("processtasks")
public class ProcessTaskController extends BaseController {
    @Autowired
    private ProcessTaskService processTaskService;

    @GetMapping("gettask")
    public AxiosResult gettask(ProcessTask task){
        startPage();
        List<ProcessTask> gettasklist = processTaskService.list(new QueryWrapper<ProcessTask>(task));
        TableDatas list = new TableDatas(gettasklist);
        return AxiosResult.suc(list);
    }

    @GetMapping("getOneById")
    public AxiosResult getOneById(String id){
        ProcessTask ProcessTasks = processTaskService.getById(id);
        return AxiosResult.suc(ProcessTasks);
    }

    @PostMapping
    public  AxiosResult insert(@RequestBody ProcessTask processTasks ){
        boolean flag =  processTaskService.save(processTasks);
        return isok(flag);
    }

    @PutMapping
    public  AxiosResult updateByid(@RequestBody ProcessTask ProcessTasks){
        boolean flag =  processTaskService.updateById(ProcessTasks);
        return isok(flag);
    }
    @DeleteMapping
    public  AxiosResult delById(String ids) {
        String[] myid = ids.split(",");
        boolean flag =  processTaskService.removeByIds(Arrays.asList(myid));
        return isok(flag);
    }
}
